package com.example.demo.controller.rmqp2;

import com.example.demo.controller.rmqp.RmqpConnection;
import com.rabbitmq.client.CancelCallback;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.DeliverCallback;

/**
 * @author 高俊
 * @create 2021-08-2021/8/14-17:21
 */
public class RmqpWork1 {

    public static void main(String[] args) throws Exception {
        System.out.println("C1接收时间较短");
        Channel connection = RmqpConnection.getConnection();
        DeliverCallback deliverCallback = (tag,msg) ->{

            try {
                Thread.sleep(1000);
                System.out.println("C1接收消息成功:" + new String(msg.getBody(),"UTF-8"));
                connection.basicAck(msg.getEnvelope().getDeliveryTag(),false);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        };

        CancelCallback cancelCallback = tag->{
            System.out.println("取消了消息发送......");
        };




        connection.basicConsume(RmqpConnection.NEW_QUENE,false,deliverCallback,cancelCallback);
    }
}
